package com.appspot.codelab.docs.client.repository;


import com.appspot.codelab.docs.client.impl.Map;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayString;

public class RepositoryDirectory extends JavaScriptObject {

  protected RepositoryDirectory() { }
  
  public final native String getName() /*-{
  	return this.name;
  }-*/;
  
  public final native int getTotalFiles() /*-{
    return this.totalFiles;
  }-*/;
  
  public final native int getTotalFilePages() /*-{
    return this.totalFilePages;
  }-*/;
  
  public final native RepositoryFilePage getFilePage() /*-{
    return this.filePage;
  }-*/;
  
  public final native Map<RepositoryDirectory> getSubDirs() /*-{
  	if (!this.hasNames) {
  	  for (var dir in this.subdirs) this.subdirs[dir].name = dir;
  	  this.hasNames = true;
  	}
    return this.subdirs;
  }-*/;
  
  public final native int getTotalSubdirs() /*-{
    return this.totalSubdirs;
  }-*/;
  
  public final native int getTotalSubdirPages() /*-{
    return this.totalSubdirPages;
  }-*/;
  
  public static class RepositoryFilePage extends JavaScriptObject {
	  
	protected RepositoryFilePage() { }
	  
	public final native Map<RepositoryFile> getFiles() /*-{
  	  if (!this.hasNames) {
  	    for (var file in this.files) this.files[file].push(file);
  	    this.hasNames = true;
  	  }
	  return this.files;
	}-*/;
	
	public final native int getPageNum() /*-{
	  return this.pageNum;
	}-*/;
	  
	public final native int getFileCount() /*-{
	  return this.fileCount;
	}-*/;
	  
	public final native int getOffset() /*-{
	  return this.offset;
	}-*/;
	
  }
  
  public static class RepositoryFile extends JsArrayString {
	
	protected RepositoryFile() { }
	
	public final String getName() {
	  return this.get(4);
	}

	public final String getSizeLabel() {
	  return this.get(0);
	}

	public final String getRevisionLabel() {
	  return this.get(1);
	}

	public final String getModifiedLabel() {
	  return this.get(2);
	}

	public final String getAuthorLabel() {
	  return this.get(3);
	}
	
	public static final native RepositoryFile newInstance(String author) /*-{
	  return ["0 bytes",null,null,author];
	}-*/;
	
  }
  
}